package com.xforceplus.bsstool.service;


import com.xforceplus.bsstool.config.ConfigMain;
import com.xforceplus.bsstool.log.LogMain;

import java.util.List;
import java.util.Map;

public class ServiceCommon {
  //比对Map值
  public static boolean compareMapValue(Map sourceMap, Map targetMap, List<String> compareKeyList, String prefix, LogMain logger) throws Exception{
    boolean result = true;
    for (String key : compareKeyList ){
      logger.info("执行"+key+"比对");
      if (!sourceMap.get(key).equals(targetMap.get(key))){
        logger.error(prefix+"  "+key+"不匹配  新运营"+key+":"+targetMap.get(key) +"  期望"+key+":"+sourceMap.get(key));
        result = false;
      }else {
        logger.info(prefix+"  "+key+"比对通过！！！");
      }
    }
    return result;
  }

  //获取功能集in语句
  public static String getResourceSetIdInSql(){
    StringBuilder sql = new StringBuilder();
    sql.append("  in(");
    int index = 0;
    for (Long resourcesetId: ConfigMain.RESOURCE_SET_IDS){
      if (index == 0){
        sql.append(resourcesetId);
      }else {
        sql.append(",").append(resourcesetId);
      }
      index ++;
    }
    sql.append(")");

    return sql.toString();
  }

  //获取租户ID in语句
  public static String getTenantIdInSql(List<Long> tenantIdList){
    StringBuilder sql = new StringBuilder();
    sql.append("  in(");
    int index = 0;
    for (Long tenantId: tenantIdList){
      if (index == 0){
        sql.append(tenantId);
      }else {
        sql.append(",").append(tenantId);
      }
      index ++;
    }
    sql.append(")");

    return sql.toString();
  }

  //获取公司ID in语句
  public static String getCompanyIdInSql(List<Long> companyIdList){
    StringBuilder sql = new StringBuilder();
    sql.append("  in(");
    int index = 0;
    for (Long companyId: companyIdList){
      if (index == 0){
        sql.append(companyId);
      }else {
        sql.append(", ").append(companyId);
      }
      index ++;
    }
    sql.append(") ");

    return sql.toString();
  }
}
